package fr.opensagres.xdocreport.examples.xhtml;

import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLConverter;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.*;

/**
 * @author yzc
 * @description  不推荐使用，转换效果差
 * @date 2018/9/6
 */
public class ConvertDocxToXHTML {

    /**
     * 转出来的HTML中图片违法显示，且图片指向路径"word/media/imageX.png"
     * @param args
     */
    public static void main(String[] args) {
        String fileIn = "/Users/yuanzhenchao/tmp/3.docx";
        String fileOut = "/Users/yuanzhenchao/tmp/test3.html";
        long startTime = System.currentTimeMillis();
        try {
            // 1) Load docx with POI XWPFDocument
            InputStream in = new FileInputStream(fileIn);
            XWPFDocument document = new XWPFDocument(in);

            // 2) Convert POI XWPFDocument 2 PDF with iText
            OutputStream out = new FileOutputStream(new File(fileOut));
            PdfOptions options = null;
            XHTMLConverter.getInstance().convert(document, out, null);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println( "Generate html with " + ( System.currentTimeMillis() - startTime ) + " ms." );
    }
}
